package br.com.iqt;

import br.com.iqt.exception.DbmsException;
import br.com.iqt.exception.HeuristicsSelectedException;
import br.com.iqt.exception.SqlInputException;
import br.com.iqt.midlleware.Midlleware;
import br.com.iqt.util.Indenter;
import br.com.iqt.zql.ParseException;
import br.com.iqt.zql.ZConstant;
import br.com.iqt.zql.ZExp;
import br.com.iqt.zql.ZExpression;
import br.com.iqt.zql.ZQuery;
import br.com.iqt.zql.ZSelectItem;
import br.com.iqt.zql.ZStatement;
import br.com.iqt.zql.ZqlParser;
import java.beans.Expression;
import java.io.ByteArrayInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.SQLException;
import java.util.Collection;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;



/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author Arlino
 */

public class StringDemo {
    
    public static void main(String args[]){
        /*
        try{
            String sql = "select pg_stat_get_backend_activity(s.backendid) as current_query from (select pg_stat_get_backend_idset() as backendid) as s;";
            ZqlParser p = new ZqlParser();
            p.initParser(new ByteArrayInputStream(sql.getBytes()));
            ZStatement st = p.readStatement();
            
            System.out.println(st);
            Midlleware md = new Midlleware(new Dbms(Dbms.POSTGRESQL, "localhost2", "5432", "tpch", "postgres", "123456"), AgentRewriter.heuristicCash);
            md.executeQuery("SELECT * FROM orders where o_totalprice < ALL ( SELECT o_totalprice FROM orders where o_orderpriority = '2-HIGH')");
        }catch(Exception e){
            //** Criar excessao
            System.out.println("Erro=" + e.getMessage());
        }
        */ 


        
Midlleware md = null;
        try {
            md = new Midlleware(new Dbms(Dbms.POSTGRESQL, "localhost", "5432", "tpch", "postgres", "123456"), AgentRewriter.sqlCash);
        } catch (FileNotFoundException ex) {
            Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        }
        
        try {
            md.executeQuery("SELECT * FROM orders where o_totalprice < ALL ( SELECT o_totalprice FROM orders where o_orderpriority = '2-HIGH')");
            md.close();
        } catch (SqlInputException ex) {
            System.out.println("Erro1: " + ex.getMessage());
            //Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (java.text.ParseException ex) {
            System.out.println("Erro2: " + ex.getMessage());
            //Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ParseException ex) {
            System.out.println("Erro3: " + ex.getMessage());
            //Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (ClassNotFoundException ex) {
            System.out.println("Erro4: " + ex.getMessage());
            //Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (SQLException ex) {
            System.out.println("Erro5: " + ex.getMessage());
            //Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (FileNotFoundException ex) {
            System.out.println("Erro6: " + ex.getMessage());
            //Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            System.out.println("Erro7: " + ex.getMessage());
            //Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (DbmsException ex) {
            System.out.println("Erro8: " + ex.getMessage());
            //Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        } catch (HeuristicsSelectedException ex) {
            System.out.println("Erro9: " + ex.getMessage());
            //Logger.getLogger(StringDemo.class.getName()).log(Level.SEVERE, null, ex);
        }
        
     
    }

};

